import random

while True:
    level = int(input("请输入游戏难度:1.(1,100),2.(1,1000),3.(1,10000))\n"))
    if level == 1:
        answer = random.randint(1, 100)
    elif level == 2:
        answer = random.randint(1, 1000)
    elif level == 3:
        answer = random.randint(1, 10000)
    else:
        print("输入错误，请重新输入")
        continue

    print("游戏开始！")

    while True:
        try:
            user = int(input("请输入一个整数:"))
            if user == answer:
                print("bingo!恭喜你！猜对了！")
                break
            elif user > answer:
                print("抱歉，你输入的数字偏大了，请输入")
            else:
                print("抱歉，你输入的数字偏小了，请输入")
        except ValueError:
            print("输入错误，请重新输入一个有效整数！")
